package com.ybwh.springboot2.validator;

import com.ybwh.springboot2.valid.UnionFieldValidator;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class LevelUnionFieldValidator implements UnionFieldValidator<SettleInfo> {

    public static final LocalDate d1990 = LocalDate.parse("1990-01-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    public static final LocalDate d2000 = LocalDate.parse("2000-01-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    public static final LocalDate d2010 = LocalDate.parse("2010-01-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));


    @Override
    public Result valid(SettleInfo objValue) {

        if (null == objValue.getBirth()) {

            return new Result(true, "");

        }


        if (objValue.getBirth().compareTo(d1990) >= 0 && objValue.getBirth().compareTo(d2000) < 0) {
            if (!"90后".equals(objValue.getLevel())) {
                return new Result(false, "level 不对，应为  90后");
            }

        }

        if (objValue.getBirth().compareTo(d2000) >= 0 && objValue.getBirth().compareTo(d2010) < 0) {
            if (!"00后".equals(objValue.getLevel())) {
                return new Result(false, "level 不对，应为  00后");
            }

        }

        return new Result(true, "");
    }
}
